package models
{
	import flash.filesystem.File;
	import flash.filesystem.FileMode;
	import flash.filesystem.FileStream;
	
	import mx.controls.Alert;
	
	[Bindable]
	public class ModelLocator
	{
		public var lastID:int;
		public var hoticon:String;
		public var output:String;
		public var serverUrl:String;
		private static var instance:ModelLocator;  
  
        public static function getInstance():ModelLocator  
        {  
            if(instance==null)  instance = new ModelLocator();  
            return instance;  
        }  
  																											
        public function ModelLocator()  
        {  
           if(instance!=null) throw new Error("Error: Singletons can only be instantiated via getInstance() method!");  
            ModelLocator.instance = this;  
        }  
		
		public function read():void{
			//var file:File = new File("file:///F:/png2/id");
			var file:File = File.applicationStorageDirectory.resolvePath("id");
			if(!file.exists){
				Alert.show("第一次使用请配置设置！");
				return;
			}
			var fs:FileStream = new FileStream;
			fs.open(file,FileMode.READ);
			var obj:Object = fs.readObject()
			fs.close();
			if(obj == null){
				return;
			}
			lastID = obj.lastID;
			hoticon = obj.hoticon;
			output = obj.output;
			serverUrl = obj.serverUrl;
		}
		public function write():void{
			//var file:File = new File("file:///F:/png2/id");
			var file:File = File.applicationStorageDirectory.resolvePath("id");
			var fs:FileStream = new FileStream;
			fs.open(file,FileMode.WRITE);
			var obj:Object = new Object;
			obj.lastID = lastID;
			obj.hoticon = hoticon;
			obj.output = output;
			obj.serverUrl = serverUrl;
			fs.writeObject(obj);
			fs.close();
		}
	}
}